﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Lab1.QuestionSpace
{
    /// <summary>
    /// Interaction logic for Create.xaml
    /// </summary>
    public partial class Create : Page
    {
        private QuestionService qService = new QuestionService();
        public Create()
        {
            InitializeComponent();
            Question question = new Question();
            question.Root = false;
            question.Type = "Variant";
            QuestionCreateGrid.DataContext = question;
        }

        private void Save(object sender, RoutedEventArgs e)
        {
            Question question = (Question)QuestionCreateGrid.DataContext;
            if (question.Root == true && qService.getRoot() != null)
            {
                MessageBox.Show("В бд уже есть корневой вопрос!");
                return;
            }
            question.Id = Guid.NewGuid();
            qService.save(question);
            this.NavigationService.Navigate(new Index());

        }
    }
}
